/*!
 * /file WtRunner.h
 * /project	WonderTrader
 *
 * /author Wesley
 * /date 2020/03/30
 *
 * /brief
 */
#pragma once
#include <string>
#include <unordered_map>

#include "../Includes/ILogHandler.h"

#include "../WtCore/CtaStrategyMgr.h"
#include "../WtCore/EventNotifier.h"

#include "../WtCore/ActionPolicyMgr.h"
#include "../WtCore/ParserAdapter.h"
#include "../WtCore/TraderAdapter.h"
#include "../WtCore/WtCtaEngine.h"
#include "../WtCore/WtDistExecuter.h"
#include "../WtCore/WtDtMgr.h"
#include "../WtCore/WtLocalExecuter.h"

#include "../WTSTools/WTSBaseDataMgr.h"
#include "../WTSTools/WTSHotMgr.h"

NS_WTP_BEGIN
class WTSVariant;
class WtDataStorage;
NS_WTP_END

USING_NS_WTP;

class WtRunner : public ILogHandler {
public:
    WtRunner();
    ~WtRunner();

public:
    /*
     *	初始化
     */
    bool init();

    bool config();

    void run(bool bAsync = false);

private:
    bool initTraders(WTSVariant* cfgTrader);
    bool initParsers(WTSVariant* cfgParser);
    bool initExecuters(WTSVariant* cfgExecuter);
    bool initDataMgr();
    bool initEvtNotifier();
    bool initCtaStrategies();
    bool initActionPolicy();

    bool initEngine();

    //////////////////////////////////////////////////////////////////////////
    // ILogHandler
public:
    virtual void handleLogAppend(WTSLogLevel ll, const char* msg) override;

private:
    WTSVariant* _config;
    TraderAdapterMgr _traders;
    ParserAdapterMgr _parsers;
    WtExecuterFactory _exe_factory;

    WtCtaEngine _cta_engine;
    WtEngine* _engine;

    WtDataStorage* _data_store;

    WtDtMgr _data_mgr;

    WTSBaseDataMgr _bd_mgr;
    WTSHotMgr _hot_mgr;
    EventNotifier _notifier;

    CtaStrategyMgr _cta_stra_mgr;
    ActionPolicyMgr _act_policy;

    bool _is_hft;
    bool _is_sel;
};
